#include "sensor_thread.h"
#include "app_common.h"
#include "app_hs300x.h"
#include "app_isl29035.h"
#include "app_mq5.h"


/* sensor_thread entry function */
/* pvParameters contains TaskHandle_t */
void sensor_thread_entry(void * pvParameters)
{
	FSP_PARAMETER_NOT_USED(pvParameters);

	/* TODO: add your own code here */
    EventBits_t event_group_bits;
	EventBits_t waiting_eg_bits;
	
	// waiting for initialing
	waiting_eg_bits = EVENT_GROUP_SET_BIT(EVENT_GROUP_0_INIT);
	event_group_bits = xEventGroupWaitBits(event_group_0,     
											waiting_eg_bits,            
											pdFALSE,             // Do not clear event bits    
											pdTRUE,              // waiting all bits setting
											portMAX_DELAY);      // waiting forever 
    (void)event_group_bits;

	/* Initialize the Hs3003 */
	Hs300x_Init();
	/* Initialize the ISL29035 */
	Isl29035_Init();
	/* Initialize the MQ5 */
    Mq5_Init();

	while(1)
	{
		// Sampling the HS300x - timperature and humudity
		Hs300x_StartSampling();
		// sampling the isl29053 - Ambient light sensing
		Isl29035_StartSampling();
		// sampling mq5 - combustible gas
		Mq5_RunningEntry();

		// Update the sensor data every 100ms
		vTaskDelay(pdMS_TO_TICKS(100));
	}
}
